package net.lab1024.sa.admin.module.business.tests.controller;

import net.lab1024.sa.admin.module.business.tests.domain.form.TestsAddForm;
import net.lab1024.sa.admin.module.business.tests.domain.form.TestsQueryForm;
import net.lab1024.sa.admin.module.business.tests.domain.form.TestsUpdateForm;
import net.lab1024.sa.admin.module.business.tests.domain.vo.TestsVO;
import net.lab1024.sa.admin.module.business.tests.service.TestsService;
import net.lab1024.sa.base.common.controller.SupportBaseController;
import net.lab1024.sa.base.common.domain.RequestUser;
import net.lab1024.sa.base.common.domain.ValidateList;
import net.lab1024.sa.base.common.util.SmartRequestUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.time.LocalDateTime;

/**
 * cc Controller
 *
 * @Author zh
 * @Date 2024-08-20 16:01:05
 * @Copyright zz
 */

@RestController
@Tag(name = "")
public class TestsController {

    @Resource
    private TestsService testsService;

    @Operation(summary = "分页查询 @author zh")
    @PostMapping("/tests/queryPage")
    public ResponseDTO<PageResult<TestsVO>> queryPage(@RequestBody @Valid TestsQueryForm queryForm) {
        return ResponseDTO.ok(testsService.queryPage(queryForm));
    }

    @Operation(summary = "添加 @author zh")
    @PostMapping("/tests/add")
    public ResponseDTO<String> add(@RequestBody @Valid TestsAddForm addForm) {
        RequestUser requestUser = SmartRequestUtil.getRequestUser();
        addForm.setUserId(requestUser.getUserId().toString());
        addForm.setDeptId(requestUser.getDepartmentId().toString());
        addForm.setCreateTime(LocalDateTime.now());
        addForm.setUpdateTime(LocalDateTime.now());
        return testsService.add(addForm);
    }

    @Operation(summary = "更新 @author zh")
    @PostMapping("/tests/update")
    public ResponseDTO<String> update(@RequestBody @Valid TestsUpdateForm updateForm) {
        return testsService.update(updateForm);
    }

    @Operation(summary = "批量删除 @author zh")
    @PostMapping("/tests/batchDelete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Integer> idList) {
        return testsService.batchDelete(idList);
    }

    @Operation(summary = "单个删除 @author zh")
    @GetMapping("/tests/delete/{id}")
    public ResponseDTO<String> batchDelete(@PathVariable Integer id) {
        return testsService.delete(id);
    }
}
